#include <iostream>
#include <cmath>
using namespace std;

bool isPrime(int x)
{
	for(int i = 2; i <= sqrt(x); i++)
	{
		if(x % i == 0)
			return false;
	}
	return true;
}

//12121
bool ishuiwen(int x)
{
	int tmp = x;
	int ret = 0;
	while(tmp)
	{
		ret = tmp % 10 + ret * 10;
		tmp /= 10;
	}
	return ret == x;
}

int main()
{
	int n;
	cin >> n;
	int count = 0;
	for(int i = 11; i <= n; i++)
	{
		if(isPrime(i) && ishuiwen(i))
			count++;
	}
	cout << count << endl;
	return 0;
}
